package com.gh.pattern.prototype.deep;

import java.io.*;
import java.util.Date;

public class Naruto extends Person implements Cloneable,Serializable{

    public Jiuwei jiuwei;
    //鸣人
    public Naruto() {
        this.birthday = new Date();
        this.jiuwei = new Jiuwei();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Object deepClone() {

        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);

            Naruto copy = (Naruto) ois.readObject();
            copy.birthday = new Date();
            return copy;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
